<?php include_once "head.php"?>
<table class="layui-table">
    <thead>
    <tr>
        <th>祝福语</th>
        <th>添加时间</th>
        <th>修改时间</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <?php if(!empty($data)){
        foreach($data as $k=>$v){
            ?>
            <tr>
                <!--                <td><img src="--><?//=$v['host_pic']?><!--" class="tom_show_image" style="width: 80px;height:80px;"></td>-->
                <td><?=$v['name']?></td>
                <td><?=$v['add_time']?></td>
                <td><?=$v['update_time']?></td>
                <td>
                    <input type="hidden" name="" value="<?=$v['name']?>" class="old_name<?=$k+1?>">
                    <input type="hidden" name="" value="<?=$v['id']?>" class="id<?=$k+1?>">
                    <button class="layui-btn layui-btn-xs edit<?=$k+1?>">编辑</button>
                    <button class="layui-btn layui-btn-xs layui-btn-danger del<?=$k+1?>">删除</button>
                </td>
            </tr>
        <?php }} ?>

    </tbody>
</table>




<script>
    //定义一个100的jquery数组
    var arr=[];
    for(var i=1;i<101;i++){
        arr.push(i)
    }
    $.each(arr,function(i,n){
        //编辑
        $(".edit"+n).click(function(){
            var id=$(".id"+n).val();
            $.ajax({
                type: "get",
                data: {id:id},
                dataType: "json",
                url: "<?=base_url("activity/wangchun/host_one")?>",
                success: function (res) {
                    if(res.code==0){
                        html1="";
                        html1+="<div class=\"layui-form-item\">";
                        html1+="<label class=\"layui-form-label\">修改祝福语</label>";
                        html1+="<div class=\"layui-input-inline\">";
                        html1+="<input type=\"text\" name=\"title\" value="+res.data.name+" placeholder=\"请输入祝福语\" class=\"layui-input edit_name\">";
                        html1+="</div>";
                        html1+="<div class=\"layui-form-mid layui-word-aux\">不能大于20个字</div>";
                        html1+="</div>";
//                        html1+="<div class=\"layui-form-item\">";
//                        html1+="<label class=\"layui-form-label\" style=\"width:120px;\">添加封面</label>";
//                        html1+="<div class=\"layui-input-block\">";
//                        html1+="<button type=\"button\" class=\"layui-btn\" id=\"test2\"><i class=\"layui-icon\"></i>上传中封面</button>";
//                        html1+="<input type=\"text\" name=\"\" class=\"wenzi2\" style=\"width:300px;height:35px;margin-left:20px;display:none;\">";
//                        html1+="<span class=\"up2\" style=\"width:300px;height:35px;margin-left:20px;display:none;color:red;\"></span>";
//                        html1+="<input type=\"hidden\" name=\"video_url\" value="+res.data.host_pic+" class='edit_host_img_url'>";
//                        html1+="</div>";
//                        html1+="</div>";
//                        html1+="<div style=\"width: 100px;height: 100px;border: 1px solid lightgreen;margin-left: 150px;float: left;\">";
//                        html1+="<img src="+res.data.host_pic+" style='width: 100px;height: 100px;' class='edit_host_img_http'>";
//                        html1+="</div>";
//                        html1+="<span style=\"margin-left: 10px;color: gainsboro;\">建议尺寸210x168，必填</span>";
//                        html1+="<div class=\"layui-form-item\">";
//                        html1+="<label class=\"layui-form-label\" style=\"width:120px;\">添加未选中封面</label>";
//                        html1+="<div class=\"layui-input-block\">";
//                        html1+="<button type=\"button\" class=\"layui-btn\" id=\"test4\"><i class=\"layui-icon\"></i>上传未选中封面</button>";
//                        html1+="<input type=\"text\" name=\"\" class=\"wenzi4\" style=\"width:300px;height:35px;margin-left:20px;display:none;\">";
//                        html1+="<span class=\"up4\" style=\"width:300px;height:35px;margin-left:20px;display:none;color:red;\"></span>";
//                        html1+="<input type=\"hidden\" name=\"video_url\" value="+res.data.host_pic_select+" class='edit_host_img_select_url'>";
//                        html1+="</div>";
//                        html1+="</div>";
//                        html1+="<div style=\"width: 100px;height: 100px;border: 1px solid lightgreen;margin-left: 150px;float: left;\">";
//                        html1+="<img src="+res.data.host_pic_select+" style='width: 100px;height: 100px;' class='edit_host_img_select_http'>";
//                        html1+="</div>";
//                        html1+="<span style=\"margin-left: 10px;color: gainsboro;\">建议尺寸210x168，必填</span>";
                        layer.open({
                            title:"修改主持人"
                            ,content:html1
                            ,area: ['650px', '500px']
                            ,btn: ['确认', '取消']
                            ,yes: function(index, layero){
                                //按钮【按钮一】的回调
                                var edit_name=$(".edit_name").val();
                                var old_name=$(".old_name"+n).val();
//                                var edit_host_img_url=$(".edit_host_img_url").val();
//                                var edit_host_img_select_url=$(".edit_host_img_select_url").val();
                                $.ajax({
                                    type: "post",
                                    data: {edit_name:edit_name,old_name:old_name,id:id},
                                    dataType: "json",
                                    url: "<?=base_url("activity/wangchun/save_edit_add_host")?>",
                                    success: function (res) {
                                        if(res.code==0){
                                            layer.msg(res.msg,{time:2000},function(){
                                                window.location.reload()
                                            })

                                        }else{
                                            layer.msg(res.msg,{time:2000})
                                        }
                                    }
                                })
                            }
                            ,btn2: function(index, layero){
                                //按钮【按钮二】的回调

                                //return false 开启该代码可禁止点击该按钮关闭
                            }
                            ,cancel: function(){
                                //右上角关闭回调

                                //return false 开启该代码可禁止点击该按钮关闭
                            }
                        });
                        //上传视频和音频接口
                        layui.use('upload', function() {
                            var $ = layui.jquery
                                , upload = layui.upload;
                            //上传未选中封面
                            upload.render({
                                elem: '#test2'
                                , url: "<?=base_url("common/upload/normal_upload")?>"
                                , data: {type: "image"}
                                ,acceptMime: 'image/*'
                                , before: function () {
                                    $(".up2").text("上传中。。。请等待");
                                    $(".up2").show()
                                }
                                , done: function (res) {
                                    if (res.code == 0) {
                                        $(".up2").text("上传成功");
                                        $('.edit_host_img_url').val(res.data.file_url);
                                        $('.edit_host_img_http').attr("src",res.data.file_url);
                                    }
                                    if (res.code == 1) {
                                        layer.msg(res.msg, {time: 2000});
                                    }
                                }
                            })
                            //上传选中封面
                            upload.render({
                                elem: '#test4'
                                , url: "<?=base_url("common/upload/normal_upload")?>"
                                , data: {type: "image"}
                                ,acceptMime: 'image/*'
                                , before: function () {
                                    $(".up4").text("上传中。。。请等待");
                                    $(".up4").show()
                                }
                                , done: function (res) {
                                    if (res.code == 0) {
                                        $(".up4").text("上传成功");
                                        $('.edit_host_img_select_url').val(res.data.file_url);
                                        $('.edit_host_img_select_http').attr("src",res.data.file_url);
                                    }
                                    if (res.code == 1) {
                                        layer.msg(res.msg, {time: 2000});
                                    }
                                }
                            })
                        })
                    }else{
                        layer.msg(res.msg,{time:2000})
                    }
                }
            })


        })

        //删除
        $(".del"+n).click(function(){
            var id=$(".id"+n).val();
            $.ajax({
                type: "post",
                data: {id:id},
                dataType: "json",
                url: "<?=base_url("activity/wangchun/host_del")?>",
                success: function (res) {
                    if(res.code==0){
                        layer.msg(res.msg,{time:2000},function(){
                            window.location.reload()
                        })
                    }else{
                        layer.msg(res.msg,{time:2000})
                    }
                }
            })
        })
    })

    //新增祝福语
    $(".add_host").click(function(){
        $.ajax({
            type: "get",
            data: {},
            dataType: "json",
            url: "<?=base_url("activity/wangchun/select_add_host")?>",
            success: function (res) {
                if(res.code==0){

                    html1="";
                    html1+="<div class=\"layui-form-item\">";
                    html1+="<label class=\"layui-form-label\">添加祝福语</label>";
                    html1+="<div class=\"layui-input-inline\">";
                    html1+="<input type=\"text\" name=\"title\" value=\"\" placeholder=\"请输入祝福语\" class=\"layui-input host_name\">";
                    html1+="</div>";
                    html1+="<div class=\"layui-form-mid layui-word-aux\">不能大于20个字</div>";
                    html1+="</div>";
//                    html1+="<div class=\"layui-form-item\">";
//                    html1+="<label class=\"layui-form-label\" style=\"width:120px;\">添加封面</label>";
//                    html1+="<div class=\"layui-input-block\">";
//                    html1+="<button type=\"button\" class=\"layui-btn\" id=\"test1\"><i class=\"layui-icon\"></i>上传封面</button>";
//                    html1+="<input type=\"text\" name=\"\" class=\"wenzi1\" style=\"width:300px;height:35px;margin-left:20px;display:none;\">";
//                    html1+="<span class=\"up1\" style=\"width:300px;height:35px;margin-left:20px;display:none;color:red;\"></span>";
//                    html1+="<input type=\"hidden\" name=\"video_url\" class=\"host_img_url\">";
//                    html1+="</div>";
//                    html1+="</div>";
//                    html1+="<div style=\"width: 100px;height: 100px;border: 1px solid lightgreen;margin-left: 150px;float: left;\">";
//                    html1+="<img src=\"\" style=\"width: 100px;height: 100px;\" class=\"host_img_http\">";
//                    html1+="</div>";
//                    html1+="<span style=\"margin-left: 10px;color: gainsboro;\">建议尺寸210x168，必填</span>";

                    layer.open({
                        title:"添加祝福语"
                        ,content:html1
                        ,area: ['650px', '500px']
                        ,btn: ['确认', '取消']
                        ,yes: function(index, layero){
                            //按钮【按钮一】的回调
                            var host_name=$(".host_name").val();
//                            var host_img_url=$(".host_img_url").val();
//                var host_img_select_url=$(".host_img_select_url").val();
                            $.ajax({
                                type: "post",
                                data: {host_name:host_name},
                                dataType: "json",
                                url: "<?=base_url("activity/wangchun/save_add_host")?>",
                                success: function (res) {
                                    if(res.code==0){
                                        layer.msg(res.msg,{time:2000},function(){
                                            window.location.reload()
                                        })

                                    }else{
                                        layer.msg(res.msg,{time:2000})
                                    }
                                }
                            })
                        }
                        ,btn2: function(index, layero){
                            //按钮【按钮二】的回调

                            //return false 开启该代码可禁止点击该按钮关闭
                        }
                        ,cancel: function(){
                            //右上角关闭回调

                            //return false 开启该代码可禁止点击该按钮关闭
                        }
                    });
                    //上传
                    layui.use('upload', function() {
                        var $ = layui.jquery
                            , upload = layui.upload;
                        //上传未选中封面
                        upload.render({
                            elem: '#test1'
                            , url: "<?=base_url("common/upload/normal_upload")?>"
                            , data: {type: "image"}
                            ,acceptMime: 'image/*'
                            , before: function () {
                                $(".up1").text("上传中。。。请等待");
                                $(".up1").show()
                            }
                            , done: function (res) {
                                if (res.code == 0) {
                                    $(".up1").text("上传成功");
                                    $('.host_img_url').val(res.data.file_url);
                                    $('.host_img_http').attr("src",res.data.file_url);
                                }
                                if (res.code == 1) {
                                    layer.msg(res.msg, {time: 2000});
                                }
                            }
                        })
                        //上传选中封面
                        upload.render({
                            elem: '#test3'
                            , url: "<?=base_url("common/upload/normal_upload")?>"
                            , data: {type: "image"}
                            ,acceptMime: 'image/*'
                            , before: function () {
                                $(".up3").text("上传中。。。请等待");
                                $(".up3").show()
                            }
                            , done: function (res) {
                                if (res.code == 0) {
                                    $(".up3").text("上传成功");
                                    $('.host_img_select_url').val(res.data.file_url);
                                    $('.host_img_select_http').attr("src",res.data.file_url);
                                }
                                if (res.code == 1) {
                                    layer.msg(res.msg, {time: 2000});
                                }
                            }
                        })
                    })

                }else{
                    layer.msg(res.msg,{time:2000})
                }
            }
        })


    })
</script>
